Hello Dxl Community,, I attach two small files which I wrote for doing a basic unit test of the concept of combining callback functions and eval_ to do the following (1) Run the main function (main.dxl) in the DXL editor window (2) This invokes the code written in #"include D:\\WORKAREA\ImportFunction.dxl" (3) The main Boolean variable "b_main" is assigned to bSocSuccessFlag, which is assigned a value TRUE or FALSE depending on whether the user pressed apply_cb1 or apply_cb2.
The problem is that although the function ImportFunction.dxl was executed in the line eval_(dxlCode), we do not retain the variable "bSocSuccessFlag" which was locally defined there. I would like that bSocSuccessFlag could be accessed like an extern variable like in C. However if I run Supplier Import I get
How can I make it extern? or how can produce the same effect?
Colm
MyDeveloerWorks - Wed Jun 28 03:26:54 EDT 2017 |
Re: external variables First: your include statement is wrong. it should be: #include <D:/WORKAREA/ImportFunction.dxl> Apart from that you can use the "return_" perm to return a string from eval. For simply returning a boolean value I would use this. string evalCode = " #include <myscript> if (bSocSuccessFlag) return_ \"OK\"; " string s = eval_ evalCode if (s == "OK") print "yey ;-)" Another technique is to try to put a reference inside the eval_ script and write that reference from the eval. boolean myVar = false; string evalCode = " bool &bReference = addr_ " ((addr_ (&myVar))int) " #include <myscript> bReference = bSocSuccessFlag " eval_ evalCode print "Yey: " myVar "\n" The above code will work only on 32bit. For 64 bit you need to refer to the corresponding posts on the forum (search for eval_ 64 mathias). Hope this helps, regards, Mathias |
Re: external variables Mathias Mamsch - Wed Jun 28 07:03:58 EDT 2017 First: your include statement is wrong. it should be: #include <D:/WORKAREA/ImportFunction.dxl> Apart from that you can use the "return_" perm to return a string from eval. For simply returning a boolean value I would use this. string evalCode = " #include <myscript> if (bSocSuccessFlag) return_ \"OK\"; " string s = eval_ evalCode if (s == "OK") print "yey ;-)" Another technique is to try to put a reference inside the eval_ script and write that reference from the eval. boolean myVar = false; string evalCode = " bool &bReference = addr_ " ((addr_ (&myVar))int) " #include <myscript> bReference = bSocSuccessFlag " eval_ evalCode print "Yey: " myVar "\n" The above code will work only on 32bit. For 64 bit you need to refer to the corresponding posts on the forum (search for eval_ 64 mathias). Hope this helps, regards, Mathias Hello Mathias,, Thanks for the very valuable hints and corrections. Both suggestions work well. (.... Actually I should always use the DXL lib folder so I can do a <myscript> instead of absolute paths to D: ! I slapped myself on the wrist for that. I promise not to do it again!)
Colm |